<%- set_header :title=>@command.name, :description=>@command.description -%>
<%= javascript_tag "$('header_search_query').value = '#{@command.keyword}'"%>
<h1 class="inline">
	<%= h @command.name %>
</h1>
<% if logged_in? %>
	<ul class="options header">
		<% if current_user.is_admin? %>
			<li class="edit"><%= link_to 'Edit this Command', edit_command_path(@command) %></li>
		<% end %>
		<% unless @command.created_by?(current_user) %>
			<li class="add"><%= link_to 'Copy', copy_user_command_path(:id=>@command.id, :is_command=>true) %></li>
			<li class="add"><%= link_to 'Subscribe', subscribe_user_command_path(:id=>@command.id, :is_command=>true) %></li>
		<% end %>
	</ul>
<% end %>

<hr />
<p class="small-url">
	<%= truncate_with_more h(@command.url), 150 %>
</p>

<div id="primary">
	<div style="margin: 20px 0px">
		<h2><%= link_to_function 'Description', "$('command_description_box').toggle()", :class=>"function_link" %></h2>
		<div id="command_description_box" style="font-size: 12px">
			<%= command_description @command %>
		</div>
	</div>
	<%= render :partial=>'user_commands/options_description_box', :locals=>{:command=>@command}%>
	
	<h2>
		Public Queries
		<%= "(Last #{@queries.size})" %>
	</h2>
	<% cache({:id=>@command.id, :section=>'query_table'}, :ttl=>10.minutes) do %>
	<%= query_table @queries, :columns=>[:query_string, :created_at]%>
	<% end %>
	<%= table_link_to "View all queries", command_queries_path(@command) %>
</div>


<div id="secondary">
	
	<h2>
		<%= render_favicon_for_command @command %>
		About this Command
	</h2>
	<p>Created by <%= user_link @command.user %> on <%= @command.created_at.to_s(:medium)%>.</p>
	
	<p><b>Keyword:</b> <%=h @command.keyword %></p>
	
	<p><b>Type:</b> <%= command_type_image @command.command_type.pluralize %> <%= @command.command_type.capitalize %> <%= "(uses POST)" if @command.http_post? %></p>
	<% unless @command.tags.empty? %>	
		<p><b>Tags:</b> <%= @command.tag_list.map{|tag| link_to(tag, tagged_commands_path(tag))}.join(" ") %></p>	
	<% end %>
		
	<p><b>Visible to Public:</b> <%= @command.public? ? "Yes" : "No" %></p>
	<p><b>Last Used:</b> <%= time_ago_in_words_or_date @command.updated_at %></p>
	<p><b>Number of Users:</b> <%= @command.users_count %></p>
		
	<p><b>Total Queries:</b> <%= @command.queries_count_all %></p>
	
	<% cache({:id=>@command.id, :section=>'user_tags'}, :ttl=>30.minutes) do %>
		<h2>User Tags</h2>
		<%= tag_cloud_or_list @command.user_tags, :path=>:all_users %>
	<% end %>

	<% if @command.public? && ! @user_commands.empty? %>
		<h2>Top Users of this Command</h2>
		<%= user_command_table(@user_commands, :columns=>[:user, :name, :queries_count]) %>
		<%= table_link_to "View all user commands", command_user_commands_path(@command) %>
	
	<% end %>
	
</div>